package www.reviewW.view;

import www.reviewW.data.Knowledge;
import www.reviewW.data.ModeData;
import www.reviewW.data.ReviewWData;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class KnowledgeJDialog{ //知识点添加类，此类将添加一条新的知识
    JLabel title = new JLabel("知识点标题");
    JLabel content = new JLabel("知识点描述");
    JTextField titleTextField = new JTextField(); //标题文本档
    JTextArea contentTextArea = new JTextArea();
    JButton jButton = new JButton("确定");
    JButton jButton2 = new JButton("取消");
    public KnowledgeJDialog(JFrame jFrame, ReviewWData reviewWData,ModeData modeData){
        JDialog jDialog = new JDialog(jFrame,true);
        jDialog.setTitle("添加新的知识点");
        jDialog.setSize(500,400);
        jDialog.setLocationRelativeTo(null);
        jDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        jDialog.setLayout(null);

        title.setBounds(new Rectangle(30,0,100,30));
        titleTextField.setBounds(new Rectangle(title.getWidth(),title.getY(),350,title.getHeight()));

        content.setBounds(new Rectangle(title.getX(),title.getHeight(),title.getWidth(),title.getHeight()));
        JScrollPane js = new JScrollPane(contentTextArea);

        titleTextField.setToolTipText("给新学的知识起一个名字吧!!!");
        contentTextArea.setToolTipText("写一点能够让你快速回忆它的东西，像一个问题");

        js.setBounds(new Rectangle(titleTextField.getX(),content.getY()+15,titleTextField.getWidth(),250));


        jButton.setBounds(new Rectangle(100,320,100,30));
        jButton2.setBounds(new Rectangle(340,jButton.getY(),jButton.getWidth(),jButton.getHeight()));

        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                for(ModeData modeData1:reviewWData.getModeDatas()){
                    if(modeData1 == modeData){
                        modeData1.addKnowledge(titleTextField.getText(),contentTextArea.getText());
                        try {
                            ReviewWData.ObjectOut(reviewWData);
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                }
                jDialog.dispose();
            }
        });
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jDialog.dispose();
            }
        });

        jDialog.add(title);
        jDialog.add(titleTextField);

        jDialog.add(content);
        jDialog.add(js);

        jDialog.add(jButton);
        jDialog.add(jButton2);




        jDialog.setVisible(true);
    }
    public static void main(String[] args){
    }
}
